package com.taobao.machinesystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.taobao.machinesystem.entity.McAddressbook;
import com.taobao.machinesystem.entity.McInspect;
import com.taobao.machinesystem.entity.vo.McAddressbookQueryVo;
import com.taobao.machinesystem.mapper.McAddressbookMapper;
import com.taobao.machinesystem.service.McAddressbookService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 第三方公司通讯录 服务实现类
 * </p>
 *
 * @author LiuJunCheng
 * @since 2022-04-22
 */
@Service
public class McAddressbookServiceImpl extends ServiceImpl<McAddressbookMapper, McAddressbook> implements McAddressbookService {

    @Override
    public Page<McAddressbook> listMcAddressbook(Integer currentPage, Integer size, McAddressbookQueryVo mcAddressbookQueryVo) {
        Page<McAddressbook> mcInspect = new Page<>(currentPage, size);

        QueryWrapper<McAddressbook> queryWrapper = new QueryWrapper<>();

        if (!"".equals(mcAddressbookQueryVo.getName()) && mcAddressbookQueryVo.getName() != null) {
            queryWrapper.like("name", mcAddressbookQueryVo.getName());
        }

        return baseMapper.selectPage(mcInspect, queryWrapper);
    }

    @Override
    public boolean selectBookInspectByName(String inspectPerson) {
        if (StringUtils.isEmpty(inspectPerson)) {
            return false;
        }
        QueryWrapper<McAddressbook> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", inspectPerson);

        McAddressbook mcAddressbook = baseMapper.selectOne(queryWrapper);
        if (mcAddressbook != null) {
            return true;
        }
        return false;
    }
}
